import requests
import pprint
#url='https://music.163.com/weapi/cloudsearch/get/web?csrf_token=93cbab8fd190ff31c96045f38c4ae307'
# data={
#     'params': 'xvIv5OvwO0jyDYqru5+F2679QAbuOgSeBRzVEfcw8C3IlKbGhls2urWavlUbKl3D7BGkkE/o1oz1gVWvplYVsDVponolZcbYmYCdErcfWhICO9s3egHT2fHQS/Z/a8r4AA/IZqysbPz2MnkGwqW0M7QvTFvUKOVwiLaMlkrdkeGLriOxHUiDnc9wR88YcduHHOXxIzW+B+AD7Z+ikmpMmUdLp059qkImjJopkfFqWFVdNtBG3+LDMWug3aLBBG0xkeBc6Qb8AvzDHVsJOrbtJ+3rgM74jqp5+PUNOhrD42heNWCRRGZujQGUni3EARMbUqPN+DnMH0HsqKO78jAowy8BnB1J5JXj1TX7/gWf6uE=',
#     'encSecKey': '961e3c83521cffe9de316eaadb12b87cc08bfd434f0d8dbdc5a329c5e173ab78b5dec605b43d2d37891a8322d58412907a6851c49acbf33fcc42108efe50383a0e4c6af7d65f8c3adad7958913beecea04dbabd0ab7d6e92eba7d8d2523b7994b2dde0330e205569374d9bd13992d8aab9836b233b7043d2c72938e6932d1c6b'
# }
url='https://music.163.com/weapi/cloudsearch/get/web?csrf_token=93cbab8fd190ff31c96045f38c4ae307'
# data={
#     'params': 'xvIv5OvwO0jyDYqru5+F2679QAbuOgSeBRzVEfcw8C3IlKbGhls2urWavlUbKl3D7BGkkE/o1oz1gVWvplYVsDVponolZcbYmYCdErcfWhICO9s3egHT2fHQS/Z/a8r4AA/IZqysbPz2MnkGwqW0M7QvTFvUKOVwiLaMlkrdkeGLriOxHUiDnc9wR88YcduHHOXxIzW+B+AD7Z+ikmpMmUdLp059qkImjJopkfFqWFVdNtBG3+LDMWug3aLBBG0xkeBc6Qb8AvzDHVsJOrbtJ+3rgM74jqp5+PUNOhrD42heNWCRRGZujQGUni3EARMbUqPN+DnMH0HsqKO78jAowy8BnB1J5JXj1TX7/gWf6uE=',
#     'encSecKey: 961e3c83521cffe9de316eaadb12b87cc08bfd434f0d8dbdc5a329c5e173ab78b5dec605b43d2d37891a8322d58412907a6851c49acbf33fcc42108efe50383a0e4c6af7d65f8c3adad7958913beecea04dbabd0ab7d6e92eba7d8d2523b7994b2dde0330e205569374d9bd13992d8aab9836b233b7043d2c72938e6932d1c6b'
# }
data={
    'params': 'xvIv5OvwO0jyDYqru5+F2679QAbuOgSeBRzVEfcw8C3IlKbGhls2urWavlUbKl3D7BGkkE/o1oz1gVWvplYVsDVponolZcbYmYCdErcfWhICO9s3egHT2fHQS/Z/a8r4AA/IZqysbPz2MnkGwqW0M7QvTFvUKOVwiLaMlkrdkeGLriOxHUiDnc9wR88YcduHHOXxIzW+B+AD7Z+ikmpMmUdLp059qkImjJopkfFqWFVdNtBG3+LDMWug3aLBBG0xkeBc6Qb8AvzDHVsJOrbtJ+3rgM74jqp5+PUNOhrD42heNWCRRGZujQGUni3EARMbUqPN+DnMH0HsqKO78jAowy8BnB1J5JXj1TX7/gWf6uE=',
    'encSecKey': '961e3c83521cffe9de316eaadb12b87cc08bfd434f0d8dbdc5a329c5e173ab78b5dec605b43d2d37891a8322d58412907a6851c49acbf33fcc42108efe50383a0e4c6af7d65f8c3adad7958913beecea04dbabd0ab7d6e92eba7d8d2523b7994b2dde0330e205569374d9bd13992d8aab9836b233b7043d2c72938e6932d1c6b'

}
headers = {
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'cookie':'UM_distinctid=1716941d927652-0fb3ea40be025c-335e4e71-144000-1716941d929197; __login_his_sync=0; tourist_expires=1; Hm_lvt_407473d433e871de861cf818aa1405a1=1586608862; _GUID=d8eec002-35da-1ad7-ac12-9ca1c3cb4309; CNZZDATA1261814609=674853875-1586608471-https%253A%252F%252Fwww.mkzhan.com%252F%7C1586608471; readMode=scroll; CNZZDATA1262045698=1069876723-1586605088-https%253A%252F%252Fwww.baidu.com%252F%7C1586607119; redirect_url=%2F211692%2F; Hm_lpvt_407473d433e871de861cf818aa1405a1=1586610847; cn_1262045698_dplus=%7B%22distinct_id%22%3A%20%221716941d927652-0fb3ea40be025c-335e4e71-144000-1716941d929197%22%2C%22%24_sessionid%22%3A%200%2C%22%24_sessionTime%22%3A%201586610857%2C%22%24dp%22%3A%200%2C%22%24_sessionPVTime%22%3A%201586610857%7D',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
    'referer': 'https://www.mkzhan.com/search/?keyword=%E6%96%97%E7%BD%97%E5%A4%A7%E9%99%86'
}
response=requests.post(url,data=data)
data=response.json()
id_list=data['result']['songs']
for data in id_list:
    id=data['id']
    name=data['name']+'.mp3'
    new_url='https://music.163.com/song/media/outer/url?id={}.mp3'.format(id)
    # print(new_url)
    content=requests.get(new_url,headers=headers).content
    print('正在下载{}'.format(name))
    # with open('网易云音乐//'+name,'wb')as f:
    #     f.write(content)
